package com.lq.ecoldchain.util

import android.Manifest
import android.app.Activity
import android.support.design.widget.BottomSheetDialog
import android.support.v4.app.FragmentActivity
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.view.TimePickerView
import com.lq.ecoldchain.R
import com.lq.ecoldchain.base.view.App
import com.tbruyelle.rxpermissions2.RxPermissions

/*
*2018/12/27 0027  10:43
*function by lq
*/
object PhotoShowUtils {

    /*底部 弹窗 选取照片*/
    @JvmStatic fun choosePhoto(view:View){
        val activity = view.context as FragmentActivity
        val bottomSheetDialog = BottomSheetDialog(view.context)
        val content = LayoutInflater.from(view.context).inflate(R.layout.sheet_choose_photo,null)
        val tokePhoto = content.findViewById<TextView>(R.id.take_photo)
        val choosePhoto = content.findViewById<TextView>(R.id.choose_phone)
        val photoCancel = content.findViewById<TextView>(R.id.photo_cancel)
        tokePhoto.setOnClickListener {
            RxPermissions(activity).request(Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe {
                if(it){
                    //跳转到相机
                    CameraUtil.takePhoto(activity)
                    bottomSheetDialog.dismiss()
                }else{
                    toast { "请到设置中，设置app拍照，存储权限" }
                }
            }
        }
        choosePhoto.setOnClickListener{
            RxPermissions(activity).request(Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe {
                if(it){
                    //跳转到相册
                    CameraUtil.selectImageFromLocal(activity)
                    bottomSheetDialog.dismiss()
                }else{
                    toast { "请到设置中，设置访问相册，存储权限" }
                }
            }
        }
        photoCancel.setOnClickListener {
            bottomSheetDialog.dismiss()
        }
        bottomSheetDialog.setContentView(content)
        bottomSheetDialog.show()
    }



}